{extend name="layout"/}

{block name="breadcrumb"}
<h2>{$title}</h2>
<ol class="breadcrumb">
    <li><a href="{:url('index/index')}">首页</a></li>
    <li><strong>{$title}</strong></li>
</ol>
{/block}

{block name="search"}
{include file='tie_ba/search'/}
{/block}

{block name="main"}
<div class="ibox float-e-margins">
    <div class="ibox-title">
        <h5>{$title}</h5>
    </div>
    <div class="ibox-content">
        <p>
            <button class="btn btn-danger btn-sm" onclick="actionAll('{:url("deletes", ['deleteType' => $detailType, 'oauth_id' => $search.oauth_id])}')">批量删除</button>
        </p>
        <div class="table-responsive table-elem">
            <p>共 {$count} 条数据</p>
            <table class="table table-striped">
                <thead>
                <tr>
                    <th class="checkbox-th">
                        <div class="checkbox checkbox-primary">
                            <input id="checkbox-all" type="checkbox">
                            <label for="checkbox-all"></label>
                        </div>
                    </th>
                    <th>ID</th>
                    <th>发帖用户</th>
                    <th>分类</th>
                    <th>置顶</th>
                    <th>点赞数</th>
                    <th>评论数</th>
                    <th>审核状态</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {foreach $model as $key=>$vo }
                <tr>
                    <td>
                        <div class="checkbox checkbox-primary">
                            <input id="checkbox{$vo.id}" type="checkbox" value="{$vo.id}" class="checkbox-item">
                            <label for="checkbox{$vo.id}"></label>
                        </div>
                    </td>
                    <td>{$vo.id}</td>
                    <td>{$vo.oauth_id}</td>
                    <td>{$vo.type_id}</td>
                    <td>
                        {if $vo.is_top == 1}
                        <span class="label label-info">{$vo.isTopText}</span>
                        {else/}
                        <span class="label label-warning">{$vo.isTopText}</span>
                        {/if}
                    </td>
                    <td>{$vo.praise}</td>
                    <td>{$vo.commentCount}</td>
                    <td>
                        {if $vo.check_status == 1}
                        <span class="label label-info">{$vo.checkStatusText}</span>
                        {elseif ($vo.check_status == 2)}
                        <span class="label label-danger">{$vo.checkStatusText}</span>
                        {else/}
                        <span class="label label-warning">{$vo.checkStatusText}</span>
                        {/if}
                    </td>
                    <td>{$vo.create_time}</td>
                    <td>
                        <a href="{:url('detail', ['id' => $vo.id, 'detailType' => $detailType])}" class="btn btn-success btn-xs">详情</a>
                        <a href="javascript:void(0);" data-id="{$vo.id}" class="top-one btn btn-warning btn-xs">{$vo.is_top == 1 ? '不置顶' : '置顶'}</a>
                        <a href="javascript:void(0);" data-id="{$vo.id}" class="delete-one btn btn-danger btn-xs">删除</a>
                        <a href="{:url('tie_ba_comment/index', ['tieId' => $vo.id, 'detailType' => $detailType, 'oauth_id' => $search.oauth_id])}" class="btn btn-info btn-xs">评论列表</a>
                    </td>
                </tr>
                {/foreach}
                </tbody>
            </table>
            {$model|raw}
        </div>

    </div>
</div>
{/block}

{block name="jsFile"}
{load href="/static/css/select2.min.css" /}
{load href="/static/js/select2.min.js" /}
<script>
    $('.top-one').click(function () {
        let id = $(this).data('id');
        layer.confirm('您确定要修改该数据置顶状态吗', {}, function () {
            $.ajax({
                url: "{:url('top')}",
                data: {
                    id: id
                },
                type: 'POST',
                success: function (e) {
                    layer.msg('操作成功', {icon: 1});
                    window.location.href = e.data.url;
                },
                error: function () {
                    layer.msg('操作失败', {icon: 2});
                }
            })
        });
    });

    let data = [];
    if ("{$oauth.id}" > 0) {
        data = [{'id': "{$oauth.id}", 'text': "{$oauth.nickname} | {$oauth.phone}"}];
    }
    $('.oauth_select2').select2({
        minimumInputLength: 1,//最少输入多少个字符后开始查询
        language: {
            inputTooShort: function () {
                return "请至少输入一个字符";
            }
        },
//        language: "zh-CN",
        data: data,
        ajax: {
            type: 'GET',
            url: "{:url('oauth/search')}",
            dataType: 'json',
            delay: 250,
            data: function (params) {
                return {
                    q: params.term // search term 请求参数 ， 请求框中输入的参数
                };
            }
        },
        placeholder: '请输入发帖用户',//默认文字提示
        tags: false,//允许手动添加
        allowClear: true,//允许清空
        escapeMarkup: function (markup) {
            return markup;
        }, // 自定义格式化防止xss注入
        formatResult: function formatRepo(repo) {
            return repo.text;
        }, // 函数用来渲染结果
        formatSelection: function formatRepoSelection(repo) {
            return repo.text;
        } // 函数用于呈现当前的选择
    });

</script>
{/block}